home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
015a
/
dailybat.zip
/
DAILY.BAT
Wrap
DOS Batch File
|
1990-08-13
|
5KB
|
131 lines
DOING IT DAILY KEEP YOUR SYSTEM RUNNING RIGHT
---------------------------------------------
A Program and batch file that executes routine daily tasks.
By Chris DeVoney
You've amassed an impressive collection of batch files and utility
programs that can maintain your system, doing everything from backing up
your files to fine-tuning your hard disk. But these programs do little
good if you don't use them on a regular basis. Here's a batch file/utility
combination that puts those programs to work.
Say you want to back up one directory on Mondays and another on
Tuesdays and run a hard disk optimizer on Wednesdays. You could write a
batch file that reads the day of the week from the command line and
branches to the appropriate task. But that requires you to type the day
of the week and the batch file name -- it's too much effort. Instead,
create a program called DOW.COM, which reads the day of the week from your
PC and supplies it to DAILY.BAT, which executes your programs accordingly.
DOS assigns a number to each day of the week. For example, Sunday
is 0, Monday is 1, Tuesday is 2, and so on up to Saturday, which is 6.
The DOW.COM program reads this number from DOS and creates an exit
code, which the batch command IF ERRORLEVEL can interpret. See Dossier for
creating DOW.COM using DOS's DEBUG utility program.
CREATING DAILY.BAT
------------------
Next, create DAILY.BAT and place it in a subdirectory on the DOS PATH. The
following is an outline for DAILY.BAT:
@ECHO OFF
CLS
DOW
FOR %%D IN (0 1 2 3 4 5 6) DO IF ERRORLEVEL %%D GOTO %%D
:0
{Insert your Sunday commands}
GOTO end
:1
{Insert your Monday commands}
GOTO end
:2
{Insert your Tuesday commands}
GOTO end
:3
{Insert your Wednesday commands}
GOTO end
:4
{Insert your Thursday commands}
GOTO end
:5
{Insert your Friday commands}
GOTO end
:6
{Insert your Saturday commands}
GOTO end
:end
The first three lines of DAILY.BAT turn ECHO off, clear the screen and run
DOW.COM to generate the day of the week. (If you use a DOS version
earlier than 3.3, omit the @ in the first line). The FOR..IN..DO statement
performs the bulk of the work. The numbers in parentheses must be in
ascending order, or the IF ERRORLEVEL statement won't branch properly.
After determining which day it is, the command jumps to one of seven
corresponding labels in the batch file.
LABEL WISELY
------------
The lines following each label, represented by the notes in brackets,
execute the tasks you want accomplished in each day. Be sure that GOTO end
is the last line following each label. For instance, if on Tuesdays (label
:2) you want DOS to back up only those files you altered in the
\123\SHEETS directory, the commands might be:
:2
BACKUP C:\123\SHEETS\*.* A:/M/A
GOTO end
Be sure to include a label for each day that you plan to run the batch
file. If you run the batch file on a day without a corresponding label,
you'll get an error message. To include entries for inactive days, add
labels without instructions. For example, if you don't use your computer
on Saturdays and Sundays, but you want to include labels for those days
anyway, insert the following lines:
:0
:6
GOTO end
Labels can be entered in any order. The :5 and Friday's commands can come
before the :2 and Tuesday's commands. After you've created groups for each
day of the week, add the label :end to the end of the batch file.
DAILY.BAT can execute other batch files or programs. But despite its
capabilities, DAILY.BAT has one major drawback: It cannot run itself. You
must either adopt the discipline of running thr program every day or
automate the process and put the batch file's name at the end of your
AUTOEXEC.BAT file. If you prefer to include it elsewhere in your startup
file, execute the program with either DOS's COMMAND/C or CALL(for Version
3.3 and later) commands These two batch commands allow you to nest batch
files , or invoke one from within another.
DOSSIER
-------
DOW.COM
-------
Create DOW.COM with DEBUG.COM, the utility program included with DOS.
Using an ASCII text editor, type the following lines into a file called
DOW.SCR. Press Enter at the end of each line. (You can use uppercase or
lowercase letters; DEBUG doesn't care).
N DOW.COM
E 0100 B4 2A CD 21 B4 4C
E 0106 CD 21
RCX
8
W
Q
Now exit to DOS and type:
DEBUG < DOW.SCR